<%@page import="com.kaishengit.entity.Prod"%>
<%@page import="com.kaishengit.entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="validate.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'main.jsp' starting page</title>
    <script type="text/javascript" src="js/jquery.js"></script>
  </head>
  
  <body>
  	
  
    <h3>Welcome!<%=user.getUsername() %><a href="logout.jsp">安全退出</a></h3>
    <a href="new.jsp">new product</a><a href="shopcar.jsp">我的购物车</a>
    <p></p>
    <table border="1" width="70%">
    	<tr>
    		<th>ID</th>
    		<th>Name</th>
    		<th>Price</th>
    		<th>Action</th>
    	</tr>
		<%
			List<Prod> prodList = (List<Prod>)request.getAttribute("prodList");
			for(Prod p : prodList) {
		%>
    	<tr>
    		<td><%=p.getId() %></td>
    		<td><%=p.getProdName() %></td>
    		<td>￥<%=p.getPrice() %></td>
    		<td>
    			<a href="addcar.jsp?id=<%=p.getId()%>">放入购物车</a>
    			<a href="get.jsp?id=<%=p.getId()%>">edit</a>
    			<a class="del_link" rel="<%=p.getId()%>" href="javascript:;">delete</a>
    		</td>
    	</tr>
    	<%} %>
    
    </table>
    <script type="text/javascript">
    	$(document).ready(function(){
    		$(".del_link").click(function(){
    			var id = $(this).attr("rel");
    			if(confirm("确定要删除此数据？")) {
					window.location.href = "del.jsp?id=" + id;
    			}
    			
    		});
    		
    	});
    	
    </script>
    
    
  </body>
</html>
